package utils;

import java.io.File;

import org.apache.commons.validator.GenericValidator;

public class Checker {
	
	public static boolean isNull(Object field) {
		return field == null;
	}
	
	public static boolean isNotNull(Object field) {
		return !isNull(field);
	}
	
	public static boolean isSame(Object obj1, Object obj2) {
		return obj1 == obj2;
	}
	
	public static boolean equals(Object obj1, Object obj2) {
		return obj1.equals(obj2);
	}
	
	public static boolean isEmpty(String field) {
		return GenericValidator.isBlankOrNull(field);
	}
	
	public static boolean isInteger(String field) {
		return GenericValidator.isInt(field);
	}
	
	public static boolean isLong(String field) {
		return GenericValidator.isLong(field);
	}
	
	public static boolean isDouble(String field) {
		return GenericValidator.isDouble(field);
	}
	
	public static boolean isDate(String field, String pattern) {
		return GenericValidator.isDate(field, pattern, true);
	}
	
	public static boolean isTime(String field, String pattern) {
		return GenericValidator.isDate(field, pattern, true);
	}
	
	public static boolean isEmail(String field) {
		return GenericValidator.isEmail(field);
	}
	
	public static boolean isUrl(String field) {
		return GenericValidator.isUrl(field);
	}
	
	public static boolean isInRange(int field, int min, int max) {
        return GenericValidator.isInRange(field, min, max);
    }

	public static boolean isInRange(long field, long min, long max) {
        return GenericValidator.isInRange(field, min, max);
    }
	
	public static boolean isInRange(double field, double min, double max) {
        return GenericValidator.isInRange(field, min, max);
    }
	
	public static boolean maxLength(String field, int max) {
		return GenericValidator.maxLength(field, max);
	}

	public static boolean minLength(String field, int min) {
		return GenericValidator.minLength(field, min);
	}
	
	public static boolean matches(String field, String exp) {
		return GenericValidator.matchRegexp(field, exp);
	}
	
	public static boolean fileExists(String fileName) {
		return new File(fileName).exists();
	}
	
	public static boolean isPositive(String field) {
		if(isDouble(field)) {
			return Double.valueOf(field) >= 0;
		}
		return false;
	}
}
